package com.wgy.day43Json;


import com.google.gson.Gson;

/**
 * FileName: Student
 * Date: 2021/1/13 13:22
 * Author:cs
 * Description:
 */
public class Student {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args) {
        Student student = new Student();
        student.setName("王桂云");
        student.setAge(29);
        System.out.println(student);//这里是原始的toString  Student{name='王桂云', age=29}

        Gson gson = new Gson();//这里使用了gson的框架,专门把对象处理成json
        String json = gson.toJson(student);
        System.out.println(json);//复制这个json对象到这个网站 https://www.json.cn/  你能看到json对象
        //{"name":"王桂云","age":29}


    }
}
